import React from 'react'
import { Button } from 'antd'
import JSZip from 'jszip'
import { saveAs } from 'file-saver'
import { generateProject } from '@/utils/codeGenerator'

const ExportButton = () => {
  const handleExport = () => {
    const project = generateProject()
    const zip = new JSZip()

    Object.entries(project).forEach(([fileName, content]) => {
      zip.file(fileName, content)
    })

    zip.generateAsync({ type: 'blob' }).then((blob) => {
      saveAs(blob, 'project.zip')
    })
  }

  return (
    <Button type="primary" onClick={handleExport}>
      导出项目
    </Button>
  )
}

export default ExportButton